//
//  PersonalViewController.m
//  DriftDog
//
//  Created by rimi on 15/9/7.
//  Copyright (c) 2015年 廖马林. All rights reserved.
//

#import "PersonalViewController.h"
#import "SettingViewController.h"
#import "TabControllersManager.h"

@interface PersonalViewController ()

@property (nonatomic, strong) UIImageView *backImageView;  // 背景图片
@property (nonatomic, strong) UIImageView *headImageView;  // 头像
@property (nonatomic, strong) UILabel *nameLabel; // 名字标签

@property (nonatomic, strong) UIView *firstButtomView; // 白色底部，上面加好友的个数，和帖子的个数
@property (nonatomic, strong) UIView *secondButtomView; // 白色底部

@property (nonatomic, strong) UILabel *friendsLabel; // 好友
@property (nonatomic, strong) UILabel *friendsNumber; // 好友数量
@property (nonatomic, strong) UILabel *postLabel; // 帖子
@property (nonatomic, strong) UILabel *postNumber; // 帖子数量

- (void)initializeUserInterface;

@end

@implementation PersonalViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self initializeUserInterface];
}

#pragma mark - init

- (void)initializeUserInterface {
    
    self.view.backgroundColor = [UIColor colorWithWhite:240 / 255.f alpha:1];
    
    /* 添加父类控件 */
    [self addTitleLabelWithName:@"个人信息"];
    [self addBaseRightButtonWithImage:[UIImage imageNamed:@"设置图标.png"]];
    [self.baseRightButton addTarget:self action:@selector(respondsToBaseRightButton:) forControlEvents:UIControlEventTouchUpInside];
    
    /* 添加子类控件 */
    
    [self.view addSubview:self.backImageView];
    [self.view addSubview:self.firstButtomView];
    [self.view addSubview:self.secondButtomView];
    [self.view addSubview:self.headImageView];
    [self.view addSubview:self.nameLabel];
    
}

#pragma mark - responds event

- (void)respondsToBaseRightButton:(UIButton *)sender {

    SettingViewController *setting_vc = [[SettingViewController alloc] init];
    [[TabControllersManager sharedManager].mainTabController.navigationController pushViewController:setting_vc animated:YES];
}

#pragma mark - getter

- (UIImageView *)backImageView {

    if (!_backImageView) {
        
        _backImageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 75, ORIGIN_WIDTH, 215), NO)];
        _backImageView.image = [UIImage imageNamed:@"个人中心背景图2"];
    }
    return _backImageView;
}

- (UIImageView *)headImageView {

    if (!_headImageView) {
        
        _headImageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 0, 90, 90), NO)];
        _headImageView.center = CGPointMake(70, CGRectGetMaxY(self.backImageView.frame));
        _headImageView.backgroundColor = [UIColor yellowColor];
        _headImageView.layer.cornerRadius = _headImageView.bounds.size.height / 2;
        _headImageView.layer.borderColor = [UIColor whiteColor].CGColor;
        _headImageView.layer.borderWidth = 4 * DHFlexibleVerticalMutiplier();
    }
    return _headImageView;
}

- (UILabel *)nameLabel {

    if (!_nameLabel) {
        
        _nameLabel = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(140, 253, 170, 30), NO)];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.text = @"邓海滨是条狗";
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = [UIFont boldSystemFontOfSize:15 * DHFlexibleHorizontalMutiplier()];
    }
    return _nameLabel;
}

- (UIView *)firstButtomView {

    if (!_firstButtomView) {
        
        _firstButtomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.backImageView.frame), ORIGIN_WIDTH * DHFlexibleHorizontalMutiplier(), self.headImageView.bounds.size.height / 2 + 5* DHFlexibleVerticalMutiplier())];
        _firstButtomView.backgroundColor = [UIColor whiteColor];  // 背景色设置为白色
        [_firstButtomView addSubview:self.friendsLabel];
        [_firstButtomView addSubview:self.friendsNumber];
        [_firstButtomView addSubview:self.postLabel];
        [_firstButtomView addSubview:self.postNumber];
    }
    return _firstButtomView;
}

- (UIView *)secondButtomView {

    if (!_secondButtomView) {
        
        _secondButtomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.firstButtomView.frame) + 1, ORIGIN_WIDTH * DHFlexibleVerticalMutiplier(), self.headImageView.bounds.size.height / 2 + 5* DHFlexibleVerticalMutiplier())];
        _secondButtomView.backgroundColor = [UIColor whiteColor];  // 背景色设置为白色
    }
    return _secondButtomView;
}

- (UILabel *)friendsLabel {

    if (!_friendsLabel) {
        
        _friendsLabel = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(165, 30, 30, 15), NO)];
        _friendsLabel.textAlignment = NSTextAlignmentCenter;
        _friendsLabel.text = @"好友";
        _friendsLabel.textColor = [UIColor colorWithWhite:50 / 255.f alpha:1];
        _friendsLabel.font = [UIFont systemFontOfSize:10 * DHFlexibleVerticalMutiplier()];
    }
    return _friendsLabel;
}

- (UILabel *)friendsNumber {

    if (!_friendsNumber) {
        
        _friendsNumber = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(165, 2, 30, 30), NO)];
        _friendsNumber.textAlignment = NSTextAlignmentCenter;
        _friendsNumber.text = @"0";
        _friendsNumber.font = [UIFont systemFontOfSize:23 * DHFlexibleVerticalMutiplier()];
    }
    return _friendsNumber;
}

- (UILabel *)postLabel {

    if (!_postLabel) {
        
        _postLabel = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(290, 30, 30, 15), NO)];
        _postLabel.textAlignment = NSTextAlignmentCenter;
        _postLabel.text = @"帖子";
        _postLabel.textColor = [UIColor colorWithWhite:50 / 255.f alpha:1];
        _postLabel.font = [UIFont systemFontOfSize:10 * DHFlexibleVerticalMutiplier()];
    }
    return _postLabel;
}

- (UILabel *)postNumber {

    if (!_postNumber) {
        
        _postNumber = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(290, 2, 30, 30), NO)];
        _postNumber.textAlignment = NSTextAlignmentCenter;
        _postNumber.text = @"0";
        _postNumber.font = [UIFont systemFontOfSize:23 * DHFlexibleVerticalMutiplier()];
    }
    return _postNumber;
}

@end
